// pages/search/search.js
const { getHotSearch } = require("../api/index")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keywords:[],
    hotkey:""

  },
  //内容改变
  onChange(e){
    // console.log("改变",e.detail)
    this.setData({
      hotkey:e.detail
    })
  },
  //实现搜索
  onSearch(){
    console.log("搜索")
    wx.navigateTo({
      url: '/pages/goods/goods?search=' + this.data.hotkey,
    })
  },
  //点击搜索按钮
  onSearchClick(){
    console.log("点击搜索")
    wx.navigateTo({
      url: '/pages/goods/goods?search=' + this.data.hotkey,
    })
  },
  onLoad(){
    //搜索热门关键字
    getHotSearch().then(res =>{
      if(!res.data.msg){
        this.setData({
          keywords:res.data.data.result
        })
        // console.log(res.data.data.result)
      }
  })
  },
  clickGetKeyWord(e){
    
    wx.navigateTo({
      url: '/pages/goods/goods?search=' + e.currentTarget.dataset.hotkey,
    })
  }
  
})